This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button withi? the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library("lattice")
package <U+393C><U+3E31>lattice<U+393C><U+3E32> was built under R version 3.6.3
Map of MA
Preprocessing
head(bos_crime$DISTRICT)
[1] Brighton Dorchester West Roxbury West Roxbury
[5] South Boston Dorchester
12 Levels: Brighton Charlestown ... West Roxbury
#is.na(bos_crime)
sort(sapply(bos_crime, function(x) sum(is.na(x))), decreasing = TRUE)
REPORTING_AREA Lat
20250 19999
Long DISTRICT
19999 13239
INCIDENT_NUMBER OFFENSE_CODE
0 0
OFFENSE_CODE_GROUP OFFENSE_DESCRIPTION
0 0
SHOOTING OCCURRED_ON_DATE
0 0
YEAR MONTH
0 0
DAY_OF_WEEK HOUR
0 0
UCR_PART STREET
0 0
Location
0
glimpse(bos_crime)
Rows: 319,073
Columns: 18
$ incident_number [3m[38;5;246m<fct>[39m[23m I182070945, I182070943, I182070941, I182070940, I182070938, I182070936, I182070933, I182070932, ~
$ offense_code [3m[38;5;246m<int>[39m[23m 619, 1402, 3410, 3114, 3114, 3820, 724, 3301, 301, 3301, 3301, 3114, 3108, 2647, 3201, 3006, 330~
$ offense_code_group [3m[38;5;246m<fct>[39m[23m Larceny, Vandalism, Towed, Investigate Property, Investigate Property, Motor Vehicle Accident Re~
$ offense_description [3m[38;5;246m<fct>[39m[23m "LARCENY ALL OTHERS", "VANDALISM", "TOWED MOTOR VEHICLE", "INVESTIGATE PROPERTY", "INVESTIGATE P~
$ district [3m[38;5;246m<fct>[39m[23m Brighton, Dorchester, West Roxbury, West Roxbury, South Boston, Dorchester, Mattapan, Mattapan, ~
$ reporting_area [3m[38;5;246m<int>[39m[23m 808, 347, 151, 272, 421, 398, 330, 584, 177, 364, 913, 936, 139, 429, 469, NA, 341, 130, 901, 18~
$ shooting [3m[38;5;246m<fct>[39m[23m , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
$ occurred_on_date [3m[38;5;246m<date>[39m[23m 2018-09-02, 2018-08-21, 2018-09-03, 2018-09-03, 2018-09-03, 2018-09-03, 2018-09-03, 2018-09-03, ~
$ year [3m[38;5;246m<int>[39m[23m 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018, 2018,~
$ month [3m[38;5;246m<int>[39m[23m 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, ~
$ day_of_week [3m[38;5;246m<fct>[39m[23m Sunday, Tuesday, Monday, Monday, Monday, Monday, Monday, Monday, Monday, Monday, Monday, Monday,~
$ hour [3m[38;5;246m<int>[39m[23m 13, 0, 19, 21, 21, 21, 21, 20, 20, 20, 19, 20, 19, 20, 14, 19, 18, 17, 19, 18, 18, 18, 18, 18, 1~
$ ucr_part [3m[38;5;246m<fct>[39m[23m Part One, Part Two, Part Three, Part Three, Part Three, Part Three, Part One, Part Three, Part O~
$ street [3m[38;5;246m<fct>[39m[23m LINCOLN ST, HECLA ST, CAZENOVE ST, NEWCOMB ST, DELHI ST, TALBOT AVE, NORMANDY ST, LAWN ST, MASSA~
$ lat [3m[38;5;246m<dbl>[39m[23m 42.35779, 42.30682, 42.34659, 42.33418, 42.27537, 42.29020, 42.30607, 42.32702, 42.33152, 42.295~
$ long [3m[38;5;246m<dbl>[39m[23m -71.13937, -71.06030, -71.07243, -71.07866, -71.09036, -71.07159, -71.08273, -71.10555, -71.0708~
$ location [3m[38;5;246m<fct>[39m[23m "(42.35779134, -71.13937053)", "(42.30682138, -71.06030035)", "(42.34658879, -71.07242943)", "(4~
$ Season [3m[38;5;246m<chr>[39m[23m "Fall", "Summer", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall"~
summary(bos_crime)
incident_number offense_code
I162030584: 13 Min. : 111
I152080623: 11 1st Qu.:1001
I172013170: 10 Median :2907
I172096394: 10 Mean :2318
I182065208: 10 3rd Qu.:3201
I162001871: 9 Max. :3831
(Other) :319010
offense_code_group
Motor Vehicle Accident Response: 37132
Larceny : 25935
Medical Assistance : 23540
Investigate Person : 18750
Other : 18075
Drug Violation : 16548
(Other) :179093
offense_description
SICK/INJURED/MEDICAL - PERSON : 18783
INVESTIGATE PERSON : 18754
M/V - LEAVING SCENE - PROPERTY DAMAGE: 16323
VANDALISM : 15154
ASSAULT SIMPLE - BATTERY : 14791
VERBAL DISPUTE : 13099
(Other) :222169
district reporting_area shooting
Mattapan : 49945 Min. : 0.0 :318054
Dorchester : 42530 1st Qu.:177.0 Y: 1019
West Roxbury: 41915 Median :344.0
Charlestown : 35717 Mean :383.2
South Boston: 35442 3rd Qu.:544.0
(Other) :100285 Max. :962.0
NA's : 13239 NA's :20250
occurred_on_date year month
Min. :2015-06-15 Min. :2015 Min. : 1.00
1st Qu.:2016-04-12 1st Qu.:2016 1st Qu.: 4.00
Median :2017-01-28 Median :2017 Median : 7.00
Mean :2017-01-24 Mean :2017 Mean : 6.61
3rd Qu.:2017-11-05 3rd Qu.:2017 3rd Qu.: 9.00
Max. :2018-09-03 Max. :2018 Max. :12.00
day_of_week hour ucr_part
Friday :48495 Min. : 0.00 : 90
Monday :45679 1st Qu.: 9.00 Other : 1232
Saturday :44818 Median :14.00 Part One : 61629
Sunday :40313 Mean :13.12 Part Three:158553
Thursday :46656 3rd Qu.:18.00 Part Two : 97569
Tuesday :46383 Max. :23.00
Wednesday:46729
street lat
WASHINGTON ST : 14194 Min. :-1.00
: 10871 1st Qu.:42.30
BLUE HILL AVE : 7794 Median :42.33
BOYLSTON ST : 7221 Mean :42.21
DORCHESTER AVE: 5149 3rd Qu.:42.35
TREMONT ST : 4796 Max. :42.40
(Other) :269048 NA's :19999
long location
Min. :-71.18 (0.00000000, 0.00000000) : 19999
1st Qu.:-71.10 (42.34862382, -71.08277637): 1243
Median :-71.08 (42.36183857, -71.05976489): 1208
Mean :-70.91 (42.28482577, -71.09137369): 1121
3rd Qu.:-71.06 (42.32866284, -71.08563401): 1042
Max. : -1.00 (42.25621592, -71.12401947): 898
NA's :19999 (Other) :293562
EDA
install.packages(c("DT"))
also installing the dependency <U+393C><U+3E31>jquerylib<U+393C><U+3E32>
There is a binary version available but the
source version is later:
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/jquerylib_0.1.4.zip'
Content type 'application/zip' length 525722 bytes (513 KB)
downloaded 513 KB
package jquerylib successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\capob\AppData\Local\Temp\Rtmp0YFMUl\downloaded_packages
installing the source package <U+393C><U+3E31>DT<U+393C><U+3E32>
trying URL 'https://cran.rstudio.com/src/contrib/DT_0.20.tar.gz'
Content type 'application/x-gzip' length 1509840 bytes (1.4 MB)
downloaded 1.4 MB
* installing *source* package 'DT' ...
** package 'DT' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'DT'
finding HTML links ... done
DT-imports html
coerceValue html
dataTableAjax html
dataTableOutput html
datatable html
editData html
formatCurrency html
proxy html
replaceData html
styleInterval html
tableHeader html
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (DT)
The downloaded source packages are in
C:\Users\capob\AppData\Local\Temp\Rtmp0YFMUl\downloaded_packages
?
Add a new chunk by clicking the Insert Chunk button on the toolbar or by p?essing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the conte?ts of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.